/**
 * tzdesk系统平台
 * moonvip_admin
 * com.tz.service.user
 * IUserService.java
 * 创建人:小胡 
 * 时间：2016年12月06日 18:16:52
 *
 */
package com.tz.service.user.impl;

import java.net.URLDecoder;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import com.tz.bean.User;
import com.tz.bean.TzParams;
import com.tz.dao.user.IUserMapper;
import com.tz.service.user.IUserService;
import com.tz.util.TmStringUtils;

/**
 * 会员管理serviceImpl
 * IUserService
 * 创建人:小胡 
 * 时间：2016年12月06日 18:16:52
 * @version 1.0.0
 * 
 */
@Service
public class UserServiceImpl implements IUserService{

	@Autowired
	private IUserMapper userMapper;
	
	private static Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);
	
	@Override
	public List<User> findUsers(TzParams params){
		if(TmStringUtils.isEmpty(params.getOrder()))params.setOrder("create_time desc");
		
		List<User> restList = userMapper.findUsers(params);
		try{
			if(!CollectionUtils.isEmpty(restList)){
				for(User user : restList){
					if(user == null) 
					continue;
					
					String nickName = user.getNickname();
					if(!StringUtils.isEmpty(nickName)){
						user.setNickname(URLDecoder.decode(nickName, "utf8"));
					}
				}
			}
		}catch(Exception e){
			e.printStackTrace();
			logger.error("@findUsers发生异常：{}",e.getMessage());
		}
		return userMapper.findUsers(params);
	}

	/**
	 * 登录方法
	 * @param params 手机号 + 密码
	 * @return
	 */
	@Override
	public User getLogin(TzParams params){
		return userMapper.getLogin(params);
	}
	
	@Override
	public int count(TzParams params) {
		return userMapper.count(params);
	}

	@Override
	public User getUser(Integer id) {
		return userMapper.getUser(id);
	}

	@Override
	public int save(User user) {
		return userMapper.save(user);
	}

	@Override
	public int update(User user) {
		return userMapper.update(user);
	}

	@Override
	public int delete(TzParams params) {
		return userMapper.delete(params);
	}
}
